#include "appwindow.hpp"

AppWindow::AppWindow(SceneNode* sn):m_viewer(sn)
{
  set_title("Advanced Ergonomics Laboratory");

  // A utility class for constructing things that go into menus, which
  // we'll set up next.
  using Gtk::Menu_Helpers::MenuElem;
    using Gtk::Menu_Helpers::RadioMenuElem;
  	using Gtk::Menu_Helpers::CheckMenuElem;
  // Set up the application menu

    m_menu_app.items().push_back(MenuElem("_Reset Position", Gtk::AccelKey("i"),
                                          sigc::mem_fun(m_viewer, &Viewer::reset_position)));
    m_menu_app.items().push_back(MenuElem("_Reset Orientation", Gtk::AccelKey("o"),
                                          sigc::mem_fun(m_viewer, &Viewer::reset_orientation)));
    m_menu_app.items().push_back(MenuElem("_Reset Joints", Gtk::AccelKey("n"),
                                          sigc::mem_fun(m_viewer, &Viewer::reset_joints)));
    m_menu_app.items().push_back(MenuElem("_Reset All", Gtk::AccelKey("a"),
                                          sigc::mem_fun(m_viewer, &Viewer::reset_all)));
    m_menu_app.items().push_back(MenuElem("_Quit", Gtk::AccelKey("q"),
                                          sigc::mem_fun(*this, &AppWindow::hide)));
	// options
	m_menu_option.items().push_back(CheckMenuElem(
	"_Circle", Gtk::AccelKey("c"), sigc::mem_fun(m_viewer, &Viewer::set_circle)));
	m_menu_option.items().push_back(CheckMenuElem(
	"_Z-Buffer", Gtk::AccelKey("z"), sigc::mem_fun(m_viewer, &Viewer::set_zbuffer)));	
	m_menu_option.items().push_back(CheckMenuElem(
	"_BackCull", Gtk::AccelKey("b"), sigc::mem_fun(m_viewer, &Viewer::set_backcull)));
	m_menu_option.items().push_back(CheckMenuElem(
	"_FrontCull", Gtk::AccelKey("f"), sigc::mem_fun(m_viewer, &Viewer::set_frontcull)));
	m_viewer.set_option_menu(&m_menu_option);
	// edit
	MenuElem undo_menu("_Undo", Gtk::AccelKey("u"), sigc::mem_fun(m_viewer, &Viewer::undo));
	MenuElem redo_menu("_Redo", Gtk::AccelKey("r"), sigc::mem_fun(m_viewer, &Viewer::redo));
	m_menu_edit.items().push_back(undo_menu);
    m_menu_edit.items().push_back(redo_menu);
	m_viewer.set_undo_redo_menu(&m_menu_edit);
	
    // mode slot
    sigc::slot1<void, Viewer::Mode> mode_slot = 
  	sigc::mem_fun(m_viewer, &Viewer::set_mode);
    
    // set up the mode radio menu
    Gtk::RadioMenuItem::Group radio_group;
    m_menu_mode.items().push_back(RadioMenuElem(radio_group, "_Position/Orientation", Gtk::AccelKey("p"),
                                           sigc::bind(mode_slot, Viewer::PositionOrientation)));
    m_menu_mode.items().push_back(RadioMenuElem(radio_group, "_Joints", Gtk::AccelKey("j"),
                                           sigc::bind(mode_slot, Viewer::Joints)));
    m_viewer.set_mode_menu(&m_menu_mode);
  // Set up the menu bar
  m_menubar.items().push_back(MenuElem("_Application", m_menu_app));
	m_menubar.items().push_back(MenuElem("_Edit", m_menu_edit));
	m_menubar.items().push_back(MenuElem("_Mode", m_menu_mode));
	m_menubar.items().push_back(MenuElem("_Options", m_menu_option));
  // Pack in our widgets
  
  // First add the vertical box as our single "top" widget
  add(m_vbox);

  // Put the menubar on the top, and make it as small as possible
  m_vbox.pack_start(m_menubar, Gtk::PACK_SHRINK);
    
  // Put the viewer below the menubar. pack_start "grows" the widget
  // by default, so it'll take up the rest of the window.
  m_viewer.set_size_request(300, 300);
  m_vbox.pack_start(m_viewer);

  show_all();
}
